package com.sr.examination.main;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.lang.ref.WeakReference;

/**
 * @author JongSung
 * @Description 主界面tab栏对象
 * @date 2017/10/11 0011
 */
public enum Item {
    HOME(0);
    //    NEWS(R.string.news, R.drawable.selector_bottom_navigation_news, 1),
//    BUSINESS(1, false,false),
//    USER_CENTER(2);
    private int index;
    private WeakReference<View> root;
    private WeakReference<ImageView> imageView;
    private WeakReference<TextView> textView;
    private boolean selected = false;
    private boolean repeatableClick = true;
    /**
     * 是否需要选中状态
     * false 将不会触发Item的效果
     */
    public boolean needSelect = true;

   Item(int index) {
        this.index = index;
    }

   Item(int index, boolean needSelect) {
        this.index = index;
        this.needSelect = needSelect;
    }
    Item(int index, boolean needSelect, boolean repeatableClick) {
        this.index = index;
        this.needSelect = needSelect;
        this.repeatableClick = repeatableClick;
    }

    public boolean isSelected() {
        return selected;
    }

    public boolean isRepeatableClick() {
        return repeatableClick;
    }

    public boolean isNeedSelect() {
        return needSelect;
    }

    public int getIndex() {
        return index;
    }

    public void setRoot(View root){
        this.root = new WeakReference(root);
    }
    public View getRoot(){
        if(this.root != null){
            return root.get();
        }
        return null;
    }
    public void setImageView(ImageView imageView) {
        this.imageView = new WeakReference(imageView);
    }

    public void setTextView(TextView textView) {
        this.textView = new WeakReference(textView);
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
        if (needSelect) {
            if (imageView != null) {
                ImageView img = imageView.get();
                if (img != null) {
                    img.setSelected(selected);
                }
            }
            if (textView != null) {
                TextView txt = textView.get();
                if (txt != null) {
                    txt.setSelected(selected);
                }
            }
        }
    }
}
